package Work03.Task03;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * @Author: lu
 * @Date: 2021/9/1 21:30
 * @Description:
 */
public class StudentMapTest {
    public static void main(String[] args) {
        Map<Student,String> m1 = new HashMap<>();
        Student s1 = new Student("张飞",25);
        Student s2 = new Student("关羽",27);
        m1.put(s1,"山西省运城市盐湖区解州镇");
        m1.put(s2,"河北保定涿州市");
        //根据key取值
        for (Student s: m1.keySet()){
            System.out.println(s+":"+m1.get(s));
        }
        System.out.println("--------------------------------");
        //entrySet
        for(Map.Entry<Student,String> entry :m1.entrySet()){
            System.out.println(entry.getKey()+":"+entry.getValue());
        }
        System.out.println("--------------------------------");
        //Iterator
        Iterator<Map.Entry<Student,String>> entries = m1.entrySet().iterator();
        while(entries.hasNext()){
            Map.Entry<Student,String> entry = entries.next();
            System.out.println(entry.getKey()+":"+entry.getValue());
        }
        System.out.println("--------------------------------");
        //Lambda
        m1.forEach((Student,String)->{
            System.out.println(Student+":"+String);
                }
        );
    }
}
